<?php
//就改这两行，不要扩展名
$filename = "gdp_gmsr";
$title = "国民总收入指数";

$file_html = $filename.".html";
$file_xml = $filename.".xml";

$handle_html = fopen ( "../data/$file_html", "w" );
$handle_xml = fopen ( "../data/$file_xml", "w" );

$insert_html = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>'.$title.'</title>
</head>
<body style="overflow:hidden;">
<!-- saved from url=(0013)about:internet -->
<!-- amstock script-->
  <script type="text/javascript" src="../amchart/amstock/swfobject.js"></script>
	<div id="flashcontent">
		<strong>You need to upgrade your Flash Player</strong>
	</div>

	<script type="text/javascript">
		// <![CDATA[		
		var so = new SWFObject("../amchart/amstock/amstock.swf", "amstock", "100%", "100%", "8", "#FFFFFF");
		so.addVariable("path", "");
		so.addVariable("settings_file", encodeURIComponent("'.$filename.'.xml"));
		so.write("flashcontent");
		// ]]>
	</script>
<!-- end of amstock script -->
</body>
</html>
';

if (fwrite ( $handle_html, $insert_html ) === FALSE) {
	echo "错了 $filename";
	exit ();
}
echo "HTML写完了<br>";

$insert_xml = '<?xml version="1.0" encoding="UTF-8"?>
<!-- Only the settings with values not equal to defaults are in this file. If you want to see the
full list of available settings, check the amstock_settings.xml file in the amstock folder. -->
<settings>
  <margins>0</margins>
  <equal_spacing>false</equal_spacing>
  <redraw>true</redraw>
  <number_format>  
  	<!--
    <letters>
       <letter number="1000">K</letter>
       <letter number="1000000">M</letter>
       <letter number="1000000000">B</letter>
    </letters>   
    -->   
  </number_format>
  <data_sets> 
    <data_set did="0">
       <title>East Stock</title>
       <short>ES</short>
       <color>fec514</color>
       <file_name>'.$filename.'.csv</file_name>
       <csv>
         <reverse>true</reverse>
         <separator>,</separator>
         <date_format>YYYY-MM-DD</date_format>
         <decimal_separator>.</decimal_separator>
         <columns>
           <column>date</column>
           <column>volume</column>
           <column>close</column>
         </columns>
       </csv>
    </data_set>
  </data_sets>

  <charts>
  	<chart cid="0">
  		<height>60</height>
  		<title>Value</title>
      <border_color>#CCCCCC</border_color>
      <border_alpha>100</border_alpha>
     
      <values>
        <x>
          <bg_color>EEEEEE</bg_color>
        </x>    
        <y_left>
          <unit></unit>
          <unit_position>left</unit_position>
          <digits_after_decimal>
            <data>2</data>
          </digits_after_decimal>        
        </y_left>    
      </values>
      <legend>
        <show_date>true</show_date>
      </legend>

      <column_width>100</column_width>

  		<graphs>
  			<graph gid="0">
  				<data_sources>
  				  <close>close</close>
          </data_sources>

  				<bullet>round_outline</bullet>

  		    <legend>
            <date key="false" title="false"><![CDATA[{close}]]></date>
            <period key="false" title="false"><![CDATA[open:<b>{open}</b> low:<b>{low}</b> high:<b>{high}</b> close:<b>{close}</b>]]></period>
          </legend>         
  			</graph>  			
  		</graphs>
  	</chart>  
<!--
  	<chart cid="1">
  		<height>30</height>
  		<title>Volume</title>  		
      <border_color>#CCCCCC</border_color>
      <border_alpha>100</border_alpha>
      <grid>
        <y_left>
          <approx_count>3</approx_count>
        </y_left>
      </grid>	

      <values>
        <x>
          <enabled>false</enabled>
        </x>
      </values>

      <legend>
        <show_date>false</show_date>
      </legend>
       	
      <column_width>100</column_width>
  		<graphs>
  			<graph gid="0">
  				<type>column</type>
  				
  				
  				<data_sources>
  				  <close>volume</close>
          </data_sources>
          
          <period_value>average</period_value>
  				<alpha>0</alpha>
  				<fill_alpha>50</fill_alpha>
  		    <legend>
            <date key="false" title="false"><![CDATA[{close}]]></date>
            <period key="false" title="false"><![CDATA[open:<b>{open}</b> low:<b>{low}</b> high:<b>{high}</b> close:<b>{close}</b>]]></period>
          </legend>         
  			</graph>  			
  		</graphs>
  	</chart>  
  	-->  
 
  </charts>

  <data_set_selector>
    <enabled>false</enabled>
  </data_set_selector>
  
  <period_selector>
		<periods>		
    	<period type="MM" count="1">1M</period>
    	<period type="YYYY" count="1">1Y</period>
    	<period type="YYYY" count="5">5Y</period>
    	<period selected="true" type="YYYY" count="11">11Y</period>
    	<period type="MAX">MAX</period>
		</periods>
		
		<periods_title>Zoom:</periods_title>
		<custom_period_title>Custom period:</custom_period_title> 
  </period_selector>

  <header>
    <enabled>false</enabled>
  </header>

  <scroller>
    <graph_data_source>close</graph_data_source>
    <resize_button_style>dragger</resize_button_style>   
    <playback>
      <enabled>true</enabled>
      <speed>3</speed>
    </playback>
  </scroller>
</settings>
';

if (fwrite ( $handle_xml, $insert_xml ) === FALSE) {
	echo "错了 $filename";
	exit ();
}
echo "XML写完了";

fclose($handle_html);
fclose($handle_xml);
?>